#include "header.h"

static int N, n2;
static FILE *fh_out;
static double *k, *u, g;
static fftw_complex *a[4], *RS;

void init_prep(params_ptr in) {
  N = in->n; n2 = N/2 + 1; 
  u = fftw_malloc(sizeof(double)*N);
  k = fftw_malloc(sizeof(double)*N);
  for (int j = 0; j < in->n; j ++) {
    u[j] = 2*pi*j/N;
    k[j] = j;
    if (j > N/2) k[j] = j - N;
  }
  for (int j = 0; j < 4; j++) 
  g = in->g;
}

void write_out(fftw_complex* in, char* str) {
  fh_out = fopen(str, "w");
  fprintf(fh_out, "#1.u 2.k 3.re R 4. im R\n\n");
  for (int j = 0; j < N; j++) {
    fprintf(fh_out, "%.12e\t%.12e\t%.12e\t%.12e\n", u[j], k[j], 
                        creal(in[j]), cimag(in[j]) );
  }
  fclose(fh_out);
}

void writer_out(double* in, char* str) {
  fh_out = fopen(str, "w");
  fprintf(fh_out, "#1.u 2.k 3.re R 4. im R\n\n");
  for (int j = 0; j < n2; j++) {
    fprintf(fh_out, "%.16e\t%.16e\t%.16e\t%.16e\n", u[j], k[j], 0., in[j] );
  }
  for (int j = 0; j < n2-2; j++) fprintf(fh_out, "%.16e\t%.16e\t%.16e\t%.16e\n", u[j+n2], k[j+n2], 0. ,in[n2-2-j]);
  fclose(fh_out);
}



